package com.itheima.d4_collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/*
    目标：斗地主游戏的案例开发。
    业务需求分析:
        业务: 总共有54张牌。
        点数: "3","4","5","6","7","8","9","10","J","Q","K","A","2"
        花色: "♠", "♥", "♣", "♦"
        大小王: "👲" , "🃏"
        点数分别要组合4种花色，大小王各一张。
        斗地主：发出51张牌，剩下3张作为底牌。
 */
public class GameDemo {
    public static void main(String[] args) {
        String[] nums=new String[]{"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        String[] colors={ "♠", "♥", "♣", "♦"};
        ArrayList<Card> cards = new ArrayList<>();

        int size=0;
        for(String num:nums){
            size++;
            for(String color:colors){
                cards.add(new Card(num,color,size));
            }
        }

        Card sKing=new Card("", "🃏",++size);
        Card bKing=new Card("","👲",++size);
        Collections.addAll(cards,sKing,bKing);
        System.out.println(cards);

        Collections.shuffle(cards);
        ArrayList<Card> p1 = new ArrayList<Card>();
        ArrayList<Card> p2 = new ArrayList<Card>();
        ArrayList<Card> p3 = new ArrayList<Card>();

        int index=0;
        for(Card card:cards){
            if(index%3==0){
                p1.add(card);
            }else if(index%3==1){
                p2.add(card);
            }else{
                p3.add(card);
            }
            index++;
        }
        //p1抢到地主

        List<Card> dCards=cards.subList(cards.size()-3,cards.size());
        System.out.println("地主的牌："+dCards);
        p1.addAll(dCards);

        Collections.sort(p1, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getSize()-o2.getSize();
            }
        });
        Collections.sort(p2, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.getSize()-o1.getSize();
            }
        });
        Collections.sort(p3, new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getColor().compareTo(o2.getColor());
            }
        });
        System.out.println("地主：p1"+p1);
        System.out.println("p2"+p2);
        System.out.println("p3"+p3);


    }
}




class Card{
    private String num;
    private String color;
    private int size;

    public Card() {
    }

    public Card(String num, String color, int size) {
        this.num = num;
        this.color = color;
        this.size = size;
    }

    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    @Override
    public String toString() {
        return num+color;
    }
}





